package logic

import (
	"demo/models"
	"github.com/astaxie/beego/orm"
	"math"
)

func List(page int, name string) (int, float64, []models.Good) {
	o := orm.NewOrm()
	var g []models.Good
	//当前页
	if page == 0 {
		page = 1
	}
	//总数据数
	count, _ := o.QueryTable("good").Filter("name__contains", name).All(&g)
	//显示多少页
	showPage := 5
	//总页数
	pages := math.Ceil(float64(count) / float64(showPage))
	//偏移量
	offset := (page - 1) * showPage
	//数据
	//o.QueryTable("good").RelatedSel("goods_type").Filter("name__contains", name).Offset(offset).Limit(showPage).All
	o.QueryTable("good").Filter("name__contains", name).Offset(offset).Limit(showPage).All(&g)
	return showPage, pages, g
}
